//
// Created by YE on 2024/2/13.
//
#include "ych_error.h"

void initErrorStack(ErrorStack *stack) {
    stack->capacity = YCH_ERROR_STACK_SIZE;
    stack->top = 0;
    stack->array = (Error *) malloc(YCH_ERROR_STACK_SIZE * sizeof(Error));
    if (stack->array == NULL) {
        throw(EXCEPTION_MEMORY);
    }
}

int isEmptyErrorStack(ErrorStack *stack) {
    return stack->top== 0;
}

void pushErrorStack(ErrorStack *stack, Error error) {
    if (++stack->top > stack->capacity) {
        throw(EXCEPTION_MEMORY);
    }
    stack->array[stack->top] = error;
}
Error popErrorStack(ErrorStack* stack){
    if (stack->top <= 0) {
        throw(EXCEPTION_MEMORY);
    }
    return stack->array[stack->top--];
}

void freeErrorStack(ErrorStack *stack) {
    free(stack->array);
}

void deleteErrorStack(ErrorStack *stack) {
    freeErrorStack(stack);
    free(stack);
}